package com.fpt.edu.vn.h2tv.api.admin;

import javax.ws.rs.GET;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import com.fpt.edu.vn.h2tv.service.BookStoreInfomationService;

@Path("/info")
public class BookStoreInfomationAdminAPI {

    
    @GET
    @Produces(MediaType.APPLICATION_XML)
    public Response getBookStoreInfo(){
        return buildResponse(MediaType.APPLICATION_XML, BookStoreInfomationService.getBookStoreInfo());
    }
    
    @PUT
    @Produces(MediaType.TEXT_PLAIN)
    public Response updateBookStoreInfo(@QueryParam("CompanyName") String name, 
            @QueryParam("Address") String address, @QueryParam("Phone") String phone,
            @QueryParam("Email") String email, @QueryParam("Description") String desc){
        
        return buildResponse(MediaType.TEXT_PLAIN, BookStoreInfomationService.updateInformation(name,
                address, phone, email, desc));
    }
    
    
    private Response buildResponse(String mediaType, Object repsonse){
        return Response.ok(repsonse, mediaType)
//                .header("Access-Control-Allow-Origin", "http://localhost")
//                .header("Access-Control-Allow-Methods", "GET,POST,PUT,DELETE,OPTIONS,TRACE,HEAD,CONNECT")
//                .header("Access-Control-Allow-Credentials",true)
//                .header("Access-Control-Allow-Headers", "x-accept-charset, x-accept, origin,X-Accept-Charset,X-Accept,Content-Type,Authorization,REFERER")
                .build();
    }
}
